<template>
  <div class="app-container">
    <el-form>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" @click="handleQuery">
          查询
        </el-button>
        <!-- <el-button type="primary" @click="handleAdd" icon="el-icon-plus">
          新增
        </el-button> -->
      </el-form-item>
    </el-form>

    <el-table v-loading="loading" :data="pageList" fit stripe height="615px">
      <el-table-column
        label="序号"
        type="index"
        width="100"
        align="left"
      ></el-table-column>
      <el-table-column
        label="编号"
        prop="id"
        width="120"
        align="left"
      ></el-table-column>
      <el-table-column label="操作者" width="200" align="left" prop="username">
      </el-table-column>
      <el-table-column label="操作日期" width="220" align="left">
        <template slot-scope="scope">
          {{ scope.row.createdAt | parseTime }}
        </template>
      </el-table-column>
      <el-table-column
        label="IP"
        prop="ip"
        width="200"
        align="left"
      ></el-table-column>
      <el-table-column
        label="操作记录"
        prop="actionName"
        align="left"
        show-overflow-tooltip
      ></el-table-column>
      <!-- <el-table-column
        label="操作"
        align="left"
        width="200"
        class-name="small-padding fixed-width"
      >
        <template slot-scope="scope">
          <el-button
            type="text"
            @click="handleDelete(scope.row)"
            v-hasPermi="['/v1/rbac/user/log/delete']"
            >删除</el-button
          >
        </template>
      </el-table-column> -->
    </el-table>

    <pagination
      v-show="total > 0"
      :total="total"
      :page.sync="queryParams.page"
      :limit.sync="queryParams.size"
      @pagination="getList"
    />
  </div>
</template>

<script>
import { uesrlogList, deleteUesrlog } from "@/api/userlog";

export default {
  name: "Userlog",
  data() {
    return {
      loading: false,
      pageList: [],
      total: 0,
      queryParams: {
        page: 1,
        size: 10,
      },
    };
  },
  mounted() {
    this.getList();
  },
  methods: {
    handleQuery() {
      this.queryParams.page = 1;
      this.getList();
    },
    handleDelete(row) {
      this.$confirm("确定要删除此操作记录吗？", "提示", {
        type: "warning",
      }).then(() => {
        deleteUesrlog({ roleId: row.roleId }).then((res) => {
          if (res.code == 0) {
            this.$message({
              type: "success",
              message: "操作成功",
            });
            this.getList();
          } else {
            this.$message({
              type: "error",
              message: res.msg,
            });
          }
        });
      });
    },
    getList() {
      this.loading = true;

      uesrlogList(this.queryParams)
        .then((res) => {
          this.pageList = res.data.items || [];
          this.total = res.data.total || 0;
        })
        .finally(() => (this.loading = false));
    },
  },
};
</script>

<style></style>
